package com.desire.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author LittleDesire
 * @description
 * @date 2022-05-07 周六 17:13
 * @since 17
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    /**
     * 访问地址 <a href="http://localhost/doc.html"></a>
     * @return docket
     */
    @Bean
    public Docket createDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                // 默认为true开启
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.desire.controller"))
                .paths(PathSelectors.ant("/api/**"))
                .build();
    }

    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("玛卡巴卡系统")
                .description("接口文档")
                .contact(new Contact("littledesire","http://localhost","888888@qq.com"))
                .version("v1.0")
                .build();
    }
}
